-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for optional explicit BinarySuffix precision #47
Conversation
Yea that is definitely something that we need, I would just like to make |
Thank you for the feedback. I'm glad that I could add something useful. I happy to add a |
I've added |
array("5.000 MB", 1048576 * 5, 3), | ||
array("2.000 GB", 1073741824 * 2, 3), | ||
array("3.000 TB", 1099511627776 * 3, 3), | ||
array("1.178 PB", 1325899906842624, 3), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add some tests for precision that is bigger and lower than 3? For example, 1,2,3,4,5,6,7 ?
Hi Norbert I've improved the test as requested and added cases for exceptions. It was a worthwhile exercise as I did find an issue that has been addressed in |
Support for optional explicit BinarySuffix precision
@mostertb awesome, good job! Thanks a lot 🍻 |
When humanizing a number of bytes into the largest possible unit (as the BinarySuffix humanizer already does) you may have differing requirements in the number of decimal places you wish to show.
For example, you may which to truncate the result to a natural number if displaying the value within a paragraph or you may wish to show three decimal places if you want to still maintain information about the next largest unit.
My change gives this functionality via an optional third precision parameter to Number::binarySuffix().
The parameter being optional means that the change is non-breaking.
I have attempted to make the change in such as way that it will also be compatible with future updates to the existing hard-coded ICU 56.1 decimal formats used by BinarySuffix
Lastly, I have also updated the README to include this new functionality and provided a similar test coverage to the existing functionality.